<template>
	<view>
		<view class="uni-content">
			<view class="logs">
				<view class="cu-card" v-for="(item, index) in list" :key="index">
					<view class="cu-item">
						<view class="cu-list menu-avatar">
							<view class="cu-item">
								<view class="cu-avatar round sm" style="background-image: url(/static/jokes-default.png);"></view>
								<view class="content flex-sub">
									<view class="flex text-sm">{{ item.author }}</view>
									<view class="text-gray text-sm">{{ item.create_time }}</view>
								</view>
							</view>
						</view>
						<view class="content jokes-content">
							<view class="desc margin-lg">
								<view class="text-content">
									<view class="text-lg text-black">‍‍{{ item.content }}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				lastPage: 0,
				list: [],
				loadMoreText: "加载中...",
				showLoadMore: false
			};
		},

		onUnload() {
			this.page = 1,
			this.lastPage = 0,
			this.list = [],
			this.loadMoreText = "加载更多",
			this.showLoadMore = false;
		},
		onLoad: function (option) {
			this.getData();
		},
		onReachBottom() {
			// console.log("onReachBottom");
			if (this.page > this.lastPage) {
				this.loadMoreText = "没有更多数据了!"
				return;
			}else{
				this.showLoadMore = true;
				setTimeout(() => {
					this.getData();
				}, 300);
			}
		},
		onPullDownRefresh() {
			this.page = 1,
			this.lastPage = 0,
			this.list = [],
			this.loadMoreText = "加载更多",
			this.showLoadMore = false;
			
			setTimeout(() => {
				this.getData();
			}, 300);
		},
		methods: {
			getData:function(){
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })
				let page = this.page;
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['page='+page,'timestamp='+timestamp]);
				this.helper.req({
					api:"getJokes",
					timestamp:timestamp,
					data:{page:page},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					let current_page = res.data.data.list.current_page;
					let last_page = res.data.data.list.last_page;
					this.page = current_page + 1;
					this.lastPage = last_page;
					this.list = this.list.concat(res.data.data.list.data);

					uni.stopPullDownRefresh();
					uni.hideLoading();
				})
			},
		},
	};
</script>


<style lang="scss">
.cu-list.menu-avatar > .cu-item .content{
    left: 100upx;
    line-height: normal;
}
.cu-list.menu-avatar > .cu-item .content > uni-view:first-child {
    font-size: 26upx;
	line-height: normal;
}
</style>
